import re
infor1 = """
2138675509
 (213)8675509 
213.867.5509 
(213)-867-5509 
1(213)867-5509 
+1-213-867-5509
"""
str1 = '2138675509'
str2 = ' (213)8675509 '
str3 = '213.867.5509 '
str4 = '(213)-867-5509'
str5 = '1(213)867-5509 '
str6 = '+1-213-867-5509'

# print(re.sub(r'(\d+)',r'\1',str1))
# print(re.sub(r'[ ()]','',str2))
# print(re.sub(r'\.','',str3))
# print(re.sub(r'[()-]','',str4))
# print(re.sub(r'[()-]','',str5))
# print(re.sub(r'[+-]','',str6))
#
#
# str7 = "031-8555"
# print(re.sub(r'(\d{3})-\d{4}',r'\1',str7))

a = re.findall(r'(?:[0-9]{10}|[\s1]?\(213\).*)',infor1)
# print(a)

regx = r'(\+?1?)[ .-]?\(?(\d{3})\)?[ .-]?(\d{3})[ .-]?(\d{4})'

# print(re.search(regx,infor1).groups())


test_url = 'adada<font> adasd </font> 123 <div> awd </div>'
# print(re.search(r'<(.*?)>(.*?)</\1>',test_url,re.S).groups())
# print(re.findall(r'<(.*?)>(.*?)</\1>',test_url))

# print(re.sub(r'(\d{3})-(\d{4})',r'\1','031-8444'))

infor2 = """
    张伟 86-14870293148  \n
   王伟   +86-13285654569    \n
    王芳        15856529115    \n
 李伟         13022816340  \n
  王秀英   (86)14785720656     \n
   李秀英    17201444672    \n
    李娜         15682812452     \n
    张秀英         14326967740     \n
    刘伟  15146435743    \n
   张敏        (86)-17712576838   \n
    李静       86 14295083635  \n
    张丽     (+86) 13722348123   \n
   王静         17587918887   \n
  王丽    15493106739    \n
 李强      13786842977   \n
 张静         86-15542304386     \n
    李敏         15642387356 \n
   王敏          18627216756  \n
 王磊       17206185726   \n
    李军      17857426238     \n
   刘洋        17345352790     \n
"""

# 1.提取所有 11 位数字电话号码
# print(re.findall(r'[0-9]{11}',infor2))
# 2.提取所有 18 或 13 开头的电话号码
# print(re.findall(r'1[38][0-9]{9}',infor2,re.S))
# 3.提取所有“王”姓同学的名字
# print(re.findall(r'王\w{1,2}',infor2))
# 4.提取所有“张”姓同学的电话号码 格式为 张XX的电话号码是： XXXXXX
# print(re.sub(r'(张\w{1,2}).*(1[0-9]{10})',r'\1的电话号码是:\2',"".join(re.findall(r'(张\w{1,2}.*?\n)',infor2))))
# 5.重新排版，排版成统一的格式，去掉国家区号。
# print("".join(re.sub(r'([张李王刘]\w{1,2}).*?[\+(8]?[\+86]?[\-86]?[6)]?[)-]?([0-9]{11})',r'\1的电话: \2',infor2)).replace(" ",""))